<template>
    <view class="index_class">

        <view class="cash-cont ">
            <div class="cash_list">
            <div class="cash_tit" >
                <span>提取方式</span>
                <div> {{['余额提现','佣金提现'][this.withDrawType]}}  </div>
            </div>
            <div class="extract">
                <span>提取金额</span>
                <div class="money">
                    <text>¥</text>
                    <input type="number" v-model="txmoney" placeholder="请输入提现金额" placeholder-style="font-szie:28upx;"></div>
            </div>
            <div class="withdrawable">
                可提现金额: <span>¥{{withdraw_info.withdraw_amount}}</span>
                <view class="settess" @click="getnav('/pagesB/moneyCartSon/Mybankcard')">设置提现银行卡</view>
             </div>

        </div>


        <div class="cash_list cashbank" v-if="cards">
            <div class="u-flex">
              <image src="../../static/images/img/bank.png" class="cashimg" />
              <view class="cashname">
                <p>账号:{{cards.card_number}}</p>
                <p class="u-m-t-20">姓名:{{cards.name}}</p>
              </view>
            </div>



        </div>


        <view class="settled">
            <view class="person-button">
                <button type="warn" class="btn" @click="tixianVal">提现至银行卡</button>
            </view>
            <view class="btn-text" >每月最多提现{{txInfo.tixiancishu}}次,每次最少提现{{txInfo.tixianjine}}</view>

        </view>
              <txpwd v-on:cord_info="codeShow" :valShow='valShow'  v-on:backHied="hideAl"></txpwd>

        </view>

    </view>
</template>

<script>
    import txpwd from '../../components/txpwd.vue'

export default {
    onShow(){
        // this.getTxmxindex()
      this.getwithdrawInfo()
    },
    data(){
        return {
            txInfo:'',
            valShow:false,
            cards:'', // 银行卡信息
            wallets:'', //余额信息
            txmoney: 0, // 提现金额
            withdraw_info:{},
            withDrawType:0,
          shadowStyle: {
            backgroundImage: "none",
            paddingTop: "0",
            marginTop: "20rpx",

          }
        }
    },
    components: {
        txpwd
    },
    onNavigationBarButtonTap(e) {
        uni.navigateTo({
            url: '/pagesB/wallet/withdrawList'
        });
    },
  onLoad(option){
      this.withDrawType = +option.type
  },
    methods: {

        codeShow(index) { // 接受子组件传的值  点击的六位密码值
            this.valShow = index.backHied
            console.log(index)
            /**
             * 确认支付
             */
            this.$loading()
            this.$http.getTxmxtixian({
                pay_password:index.cord,
                price:this.txmoney
            }).then(res=>{
                if(res.status == 200) {
                    this.$toast(res.mess)
                    setTimeout(()=>{
                        this.getback()
                    },1500)
                }
            })
        },
        hideAl(bal) {
            this.valShow = bal
        },
      getwithdrawInfo(){
          //余额提现：getBanlancewithDraw type=0    //佣金提现：getwithdrawInfo  type=1
          const list = ['getBanlancewithDraw','getwithdrawInfo']
          let api =  list[this.withDrawType]
          this.$http[api]().then(res=>{
            if(this.withDrawType===0){
              this.cards =res.data.cards
              this.withdraw_info = {
                withdraw_amount:res.data.wallets.price
              }
              return
            }
                this.cards = res.data.card_info
                this.withdraw_info  = res.data.withdraw_info

          })
      },
        /**
         * 提现获取钱包及银行卡信息接口
         */
        getTxmxindex(){
            this.$http.getTxmxindex().then(res=>{
                if(res.status == 200) {
                    this.cards = res.data.cards
                    this.wallets = res.data.wallets
                    this.txInfo = res.data
                }
            })
        },
        /**
         * 提现到银行卡
         */
        tixianVal(){
            if(+this.txmoney < +this.withdraw_info.min_amount) {
              return  this.$toast(`最小提现金额为¥${this.withdraw_info.min_amount}`)

            }
            if(+this.txmoney > +this.withdraw_info.withdraw_amount) {
              return  this.$toast('可提现金额不足')

            }
            if(!this.cards) {
              return this.$toast('请先绑定提现银行卡')
            }
            if(this.withdraw_info.paypwd_status == 0) {
              return this.$showModal({content:'请先设置支付密码'}).then(res=>{
                    if(res.confirm) {
                        this.getnav('/pagesB/personalSon/setupZfpwd')
                    }
                })

            }
            this.valShow = true

        }
    }
}
</script>

<style lang="scss" scoped>
@import "uview-ui/index.scss";
.settled {
    background-color: transparent!important;
}
.btn-text {
    text-align:center;
    margin-top:17upx;
    font-size: 26upx;
    color: #999;
}
.withdrawable {
    position: relative;
}
.settess {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    font-size: 26upx;
}
.u-indent-0{
  text-indent: 0;
}
.cashbank {
  display: flex;
  align-items: center;
  padding-bottom: 20upx!important;
  margin-top: 20upx!important;
  .cashimg {
    width: 90upx;
    height: 73upx;
    margin-right: 20upx;
  }
  .cashname {
    display: flex;
    flex-direction: column;

  }

}
</style>
